package javabase.enhancestring.heapleak;

import java.util.ArrayList;
import java.util.List;

class BaseStr {
	private String str = new String(new char[200000000]);
	public String getSubStr(int beginIndex, int endIndex) {
		return str.substring(beginIndex, endIndex);
	}
}

class EnhanceStr {
	private String str = new String(new char[200000000]);
	public String getSubStr(int beginIndex, int endIndex) {
		return new String(str.substring(beginIndex, endIndex));
	}
}

public class LeakDemo {

	public static void main(String[] args) {
		List<String> list = new ArrayList<String>();
		
		System.out.println("走起：·······");
		long t1 = System.currentTimeMillis();
		for (int i = 0; i < 10000; i++) {
			// 326883
//			BaseStr baseStr = new BaseStr();
//			list.add(baseStr.getSubStr(1, 5));
			
			EnhanceStr EnhanceStr = new EnhanceStr();
			list.add(EnhanceStr.getSubStr(1, 5));
		}
		System.out.println("成功耗时：" + (System.currentTimeMillis() - t1));
	}

}
